package com.by.controller.purchase;

import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.controller.BaseController;
import com.by.entity.purchase.Enquiry;
import com.by.service.purchase.EnquiryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/enquiry")
public class EnquiryController extends BaseController {

    @Autowired
    EnquiryService enquiryService;

    @PostMapping("/wait")
    public ResultBean queryWait(@RequestBody Map map) {
        PageBean bean = enquiryService.queryWaitEnquiry(map);
        return success("待询价列表", bean);
    }

    /**
     * 根据单据id查询其下未询价的产品
     *
     * @param id
     * @return
     */
    @GetMapping("/product")
    public ResultBean queryEnquiryProduct(String id) {
        Map map = enquiryService.queryEnquiryProduct(id);
        return success("询价产品", map);
    }

    @PostMapping("/save")
    public ResultBean save(@RequestBody Enquiry enquiry){
        int rs=enquiryService.saveEnquiry(enquiry);
        return rs>0?success("保存成功"):fail("保存失败");
    }
}
